<%@ page import="BL.AccessDB"%>
<%@ page import="BL.Eintrag"%>

<%
	HttpSession sess = request.getSession();

	String[] kat = AccessDB.getKat();
	boolean katChange = false;
	String[] subKat = null;
	String[] eintraege = null;
	String selKat = request.getParameter("kategorien");
	String selSubkat = request.getParameter("subKategorien");
	String selEintrag = request.getParameter("eintraege");
	boolean selEintragZurueck = false;

	if (sess.getAttribute("geloescht") != null) {
		if ((Boolean) sess.getAttribute("geloescht") == true) {
			selEintragZurueck = true;
			sess.setAttribute("geloescht", false);
		}
	}

	if (selKat != null) {
		if (!(selKat.equals("Kategorie waehlen"))) {
			subKat = AccessDB.getSubKat(selKat);
			if (selSubkat != null) {
				if (!(selSubkat.equals("Subkategorie waehlen"))) {
					eintraege = AccessDB.getEintraegeName(selSubkat);
				} else {
					selEintrag = null;
				}
			}
		} else {
			subKat = null;
			selEintrag = null;
		}
	}
%>

<h2>Eintrag anzeigen:</h2>
<form method=post action="centralServlet" id="formi">
	<script type="text/javascript">
function test(){
	document.getElementById("eintraege").value = "Penis";
	document.getElementById("formi").submit();
}
</script>
	<input type="hidden" name="act" value="eintraegeVerwalten"></input> <select
		id="kategorie" name="kategorien" onchange=test()>
		<option>Kategorie waehlen</option>
		<%
			for (int i = 0; i < kat.length; i++) {
				if (selKat != null && selKat.equals(kat[i])) {
					out.println("<option selected>" + kat[i] + "</option>");
				} else {
					out.println("<option>" + kat[i] + "</option>");
				}
			}
		%>

	</select><br> <select id="subKategorien" name="subKategorien"
		onchange="this.form.submit()">
		<%
			if (selSubkat == null) {
		%>
		<option>Subkategorie waehlen</option>
		<%
			} else {
		%>
		<option>Subkategorie waehlen</option>
		<%
			for (int i = 0; i < subKat.length; i++) {
					if (request.getParameter("subKategorien").equals(subKat[i])) {
						out.println("<option selected>" + subKat[i]
								+ "</option>");
					} else {
						out.println("<option>" + subKat[i] + "</option>");
					}
				}
			}
		%>

	</select> <br> <select id="eintraege" name="eintraege"
		onchange="this.form.submit()">
		<%
			if (selEintrag == null) {
		%>
		<option>Eintrag waehlen</option>
		<%
			} else {
		%>
		<option>Eintrag waehlen</option>
		<%
			for (int i = 0; i < eintraege.length; i++) {
					if (request.getParameter("eintraege").equals(eintraege[i])) {
						out.println("<option selected>" + eintraege[i]
								+ "</option>");
					} else {
						out.println("<option>" + eintraege[i] + "</option>");
					}
				}
			}
		%>
	</select>

	<%
		if (request.getParameter("eintraege") != null
				&& !(selEintragZurueck)) {
			if (!(request.getParameter("eintraege")
					.equals("Eintrag waehlen"))) {
				Eintrag eintrag = AccessDB.getEintrag(
						request.getParameter("subKategorien"),
						request.getParameter("eintraege"));
	%>
	<h2>Details zum Eintrag:</h2>
	<table border="1">
		<%
			out.println("<tr><th valign='top'>Name:</th><td>"
							+ eintrag.getName() + "</td></tr>");
					out.println("<tr><th valign='top'>Beschreibung:</th><td>"
							+ eintrag.getBeschreibung() + "</td></tr>");
					out.println("<tr><th valign='top'>Lat:</th><td>"
							+ eintrag.getLat() + "</td></tr>");
					out.println("<tr><th valign='top'>Lang:</th><td>"
							+ eintrag.getLang() + "</td></tr>");
					out.println("<tr><th valign='top'>Bewertung:</th><td>"
							+ eintrag.getBewertung() + "/10</td></tr>");
					out.println("<tr><th valign='top'>Hinzugefuegt von:</th><td>"
							+ AccessDB.getUserVonEintrag(eintrag.getName())
							+ "</td></tr>");
					int[][] oeff = eintrag.getOeffnungszeiten();
					out.println("<tr><th valign='top'>Oeffnungszeiten:</th><td><b>Montag:</b><br>"
							+ AccessDB.setZeitNull(oeff[1][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[1][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[1][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[1][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[1][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[1][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[1][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[1][3]).substring(2)
							+ " Uhr<br><b>Dienstag:</b><br>"
							+ AccessDB.setZeitNull(oeff[2][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[2][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[2][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[2][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[2][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[2][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[2][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[2][3]).substring(2)
							+ " Uhr<br><b>Mittwoch:</b><br>"
							+ AccessDB.setZeitNull(oeff[3][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[3][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[3][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[3][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[3][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[3][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[3][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[3][3]).substring(2)
							+ " Uhr<br><b>Donnerstag:</b><br>"
							+ AccessDB.setZeitNull(oeff[4][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[4][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[4][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[4][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[4][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[4][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[4][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[4][3]).substring(2)
							+ " Uhr<br><b>Freitag:</b><br>"
							+ AccessDB.setZeitNull(oeff[5][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[5][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[5][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[5][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[5][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[5][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[5][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[5][3]).substring(2)
							+ " Uhr<br><b>Samstag:</b><br>"
							+ AccessDB.setZeitNull(oeff[6][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[6][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[6][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[6][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[6][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[6][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[6][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[6][3]).substring(2)
							+ " Uhr<br><b>Sonntag:</b><br>"
							+ AccessDB.setZeitNull(oeff[7][0]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[7][0]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[7][1]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[7][1]).substring(2)
							+ " Uhr und<br>"
							+ AccessDB.setZeitNull(oeff[7][2]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[7][2]).substring(2)
							+ " - "
							+ AccessDB.setZeitNull(oeff[7][3]).substring(0, 2)
							+ ":"
							+ AccessDB.setZeitNull(oeff[7][3]).substring(2)
							+ "Uhr</td></tr>");
		%>
		<tr>
			<input type="submit" name="eintrAct" value="Eintrag loeschen"></input>
		</tr>

		<%
			}
			}
		%>
	</table>


</form>


